import 'package:flutter/material.dart';

///多行文本组件
class GTMultiLineTextV3 extends StatelessWidget {
  final String text;
  final TextStyle style;

  GTMultiLineTextV3(this.text,{
    Key? key,
    required this.style,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    // 根据 fontSize 计算行高
    double lineHeight = getLineHeight(style.fontSize ?? 14);

    return Text(text, style: style.copyWith(height: lineHeight),
      textHeightBehavior: TextHeightBehavior(
        applyHeightToFirstAscent: false,
        applyHeightToLastDescent: false,
      ),);
  }

  double getLineHeight(double fontSize) {
    // 根据字体大小返回合适的行高系数
    if (fontSize >= 20) {
      return 1.3;
    } else if (fontSize >= 14) {
      return 1.4;
    } else if (fontSize == 13) {
      return 1.45;
    } else if (fontSize == 12) {
      return 1.5;
    } else if (fontSize == 11) {
      return 1.55;
    } else {
      return 1.6;
    }
  }
}
